package jok.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputStreamReaderDemo {

	public static void main(String[] args) {

		writeFromIn();

		FileDemo.deleteFile("D:/a.txt");
	}

	public static void writeFromIn() {
		BufferedWriter bw = null;
		BufferedReader br = null;

		try {
			bw = new BufferedWriter(new FileWriter("D:/a.txt"));
			// 通过InputStreamReader把 字节流 转换为 字符流
			br = new BufferedReader(new InputStreamReader(System.in));

			String line = null;

			while ((line = br.readLine()) != null) {
				if ("exit".equals(line)) {
					break;
				}
				bw.write(line);
				bw.newLine();
				bw.flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
				if (bw != null)
					bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
